home *** CD-ROM | disk | FTP | other *** search
- { %filename% -- data access methods}
- { Created %date% %time% by AppMaker}
-
- { This module contains data structures to access the data in your}
- { document's file(s). The intent is to isolate the details of the}
- { data representation into this module and to provide accessor}
- { functions for reading/writing logical pieces of the data.}
- { For your application, you will probably rewrite most of this.}
- { This module will not be regenerated by AppMaker unless you delete it.}
-
- Unit %unitname%;
- Interface
-
- Uses
- TCL,
- AMCL,
- ResourceDefs;
-
- {Define the creator type and file type for your application:}
- const
- kSignature = 'XXXX';
- kFileType = 'TEXT';
-
- type
- C%appname%Data = object (CDataFile)
- hasFile: boolean;
- itsDocument: CDocument;
-
- {define your own internal data structures:}
- itsData: Handle;
-
-
- Procedure I%appname%Data (theDocument: CDocument);
- Procedure Free; override;
-
- Procedure Close; override;
- Procedure OpenData (permission: SignedByte);
- Function Save: Boolean;
- Function SaveAs (macSFReply: SFReply): Boolean;
- Procedure Revert;
-
- Procedure ReadData;
- Function WriteData: Boolean;
- Procedure DisposeData;
-
- {accessor functions, replace these with application-specific functions:}
- Procedure Get%appname%;
- Procedure Put%appname%;
- Procedure Add%appname%;
- Procedure Delete%appname%;
-
- end; {C%Appname%Data}
-
- {----------}
- Implementation
-
- {----------}
- Procedure C%appname%Data.I%appname%Data (theDocument: CDocument);
- Begin
- inherited IDataFile;
- hasFile := false;
- itsDocument := theDocument;
-
- {your application-specific initialization}
- itsData := nil;
-
- End; {I%appname%Data}
-
- {----------}
- Procedure C%appname%Data.Free;
- Begin
- DisposeData;
- inherited Free;
- End; {Free}
-
- {----------}
- Procedure C%appname%Data.OpenData (permission: SignedByte);
- Begin
- Open (permission);
- hasFile := true;
-
- ReadData;
-
- End; {OpenData}
-
- {----------}
- Procedure C%appname%Data.Close;
- Begin
- inherited Close;
- hasFile := false;
- {don't DisposeData because data may be needed by SaveAs}
- End; {Close}
-
- {----------}
- Function C%appname%Data.Save: Boolean;
- Begin
- if hasFile then begin
- Save := WriteData;
- end else begin
- {shouldn't be called in this case}
- Save := false;
- end;
- End; {Save}
-
- {----------}
- Function C%appname%Data.SaveAs (macSFReply: SFReply): Boolean;
- var
- ignoreErr: OSErr;
- Begin
- { If all of your data is in memory, then just close the current file}
- { create and open a file, then save your data into the new file}
-
- { If some of your data is in the current file and not in memory,}
- { you may have to create and open the new file,}
- { copy data from the current file to the new file,}
- { close the current file,}
- { then save your data into the new file}
-
- if hasFile then begin
- Close;
- end;
- SFSpecify (macSFReply);
- ignoreErr := HDelete (volNum, dirID, name); {in case already exists}
- CreateNew (gSignature, kFileType);
- Open (fsRdWrPerm);
- hasFile := true;
-
- SaveAs := Save;
- End; {SaveAs}
-
- {----------}
- Procedure C%appname%Data.Revert;
- Begin
- DisposeData;
- if hasFile then begin
- ReadData;
- end;
- End; {Revert}
-
-
- { The next few methods are for transferring data between the }
- { data file and your internal data structures, and for disposing}
- { your data structures. They are called by Open, Close, etc.}
- { Replace their bodies with whatever is suitable for your application}
-
- { define internal data structures to describe the file format:}
- type
- fileData = record
- stuff: integer;
- end;
-
- {----------}
- Procedure C%appname%Data.ReadData;
- Begin
- itsData := ReadAll;
- End; {ReadData}
-
- {----------}
- Function C%appname%Data.WriteData: Boolean;
- Begin
- WriteAll (itsData);
- WriteData := true;
- End; {WriteData}
-
- {----------}
- Procedure C%appname%Data.DisposeData;
- Begin
- if itsData <> nil then begin
- DisposHandle (itsData);
- itsData := nil;
- end;
- End; {DisposeData}
-
-
- { The remaining methods are for accessing your data as logical chunks.}
- { These are just models for your own accessor functions;}
- { they aren't called by any AppMaker-generated code.}
- { Replace them with whatever is suitable for your application.}
-
- {----------}
- Procedure C%appname%Data.Get%appname%;
- Begin
- End; {Get%appname%}
-
- {----------}
- Procedure C%appname%Data.Put%appname%;
- Begin
- End; {Put%appname%}
-
- {----------}
- Procedure C%appname%Data.Add%appname%;
- Begin
- End; {Add%appname%}
-
- {----------}
- Procedure C%appname%Data.Delete%appname%;
- Begin
- End; {Delete%appname%}
-
- End. {%unitname%}
-